<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}
$sql = "SELECT * FROM user";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $event = array(
             'id' => $row['id'],
        'name' => $row['name'],
        'college'=>$row['college'],
        'grade'=>$row['grade']
        );
        $data[] = $event;
    }

    print json_encode($data);
} else {
    $response = array('error' => '未找到数据');
    echo json_encode($response);
}

$conn->close();
?>
